#pragma once

#include <iostream>
#include "BoundingBox.h"

#define MD3_MAGIC	0x33504449
#define MD3_VERSION	15

struct Md3Header
{
public:
	int Magic;
	int Version;
	char Name[64];
	int Flags;
	int FrameCount;
	int TagCount;
	int MeshCount;
	int SkinCount;
	int FrameOffset;
	int TagOffset;
	int MeshOffset;
	int FileSize;
};

struct Md3Bone
{
	BoundingBox BoundingBox;
	Vector3f	Position;
	float		Scale;
	char		Creator[16];
};

struct Md3Frame
{
public:
	BoundingBox BoundingBox;
	BoundingSphere BoundingSphere;
	char	Name[16];
};

struct Md3Tag
{
public:
	char Name[64];
	Vector3f Origin;
	Vector3f Axis[3];	// 3x3 rotation matrix associated with the Tag
};

struct Md3Skin
{
	char Name[64];
	int Index;
};

struct Md3Triangle
{
	int Indices[3];
};

struct Md3Vertex
{
	Vector3s Position;
	unsigned char Normal[2];
};

struct Md3MeshInformation
{
	int Magic;
	char Name[64];
	int Flags;
	int FrameCount;
	int SkinCount;
	int VertexCount;
	int TriangleCount;
	int TriangleOffset;
	int SkinOffset;
	int TextureCoordinateOffset;
	int VertexOffset;
};

struct Md3Mesh
{
	Md3Skin* Skins;	// TODO: Might need to seperate into Info and actual.
	Md3Triangle* Triangles;
	Vector2f* TextureCoordinates;
	Md3Vertex*	Vertices;
};

class Md3
{
public:
	Md3();
	~Md3();
public:
	void Load(std::string path);
private:
	Md3Header	m_oHeader;
	Md3Frame*	m_pFrames;
	Md3Tag*		m_pTags;
	Md3Mesh*	m_pMeshs;
};